<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/9
 * Time: 12:02
 */

namespace app\flower\controller;
use cmf\controller\AdminBaseController;
use app\flower\model\FlowerAddressModel;
class AdminAddressController extends AdminBaseController
{
    /**
     * 提货点列表页
     */
    public function index(){
          $flowers = new FlowerAddressModel();
          $result = $flowers->paginate(10);
          $page = $result->render();
          $this->assign('address',$result);
          $this->assign('page',$page);
          return $this->fetch();
    }

    /**
     * 提货点添加页面
     */
    public function address(){
        return $this->fetch('address');
    }

    /**
     * 提货点修改
     */
    public function addressedit(){
        $id = input('id');
        $flowers = new FlowerAddressModel();
        $result = $flowers->get($id);
        $this->assign('result',$result);
        return $this->fetch('addressedit');
    }

    /**
     * 修改提货点
     *
     */
    public function editAddress(){
        $id = input('addressid');
        $address = input('address');
        $flowers = new FlowerAddressModel();

        $result = $flowers->where(array('id'=>$id))->update(array('address'=>$address,'dottime'=>time()));
        if($result>0){
           $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
    /**
     * 提货点添加
     * address:输入的提货地址
     */
    public function addressadd(){
        $address = input('address');
        if(empty($address)){
            $this->error('请输入提货地址再提交');
        }
        $flowers = new FlowerAddressModel();
        $flowers->address = $address;
        $flowers->dottime = time();
        $result = $flowers->save();
        if($result!=false){
            $this->success('添加成功');
        }else{
            $this->error('添加失败');
        }
    }

    /**
     * 提货点删除
     * id:提货地址对应的id
     */
    public function  addressdelete(){
        $id = input('id');
        $flowers = new FlowerAddressModel();
        $result = $flowers->where(array('id'=>$id))->delete();
        if($result!=false){
            $this->success('删除成功');
        }else{
            $this->success('删除失败');
        }
    }
}